import {CHANGE_LANGUAGE, LanguageActionTypes} from './languageActions'

interface LanguageState {
  language: "en" | "zh",
  languageList: {name: string, code: string}[]
}

const defaultState: LanguageState = {
  language: 'zh',
  languageList: [
    {
      name: '中文',
      code: 'zh'
    },
    {
      name: '英文',
      code: 'en'
    }
  ]
}
// LanguageActionTypes reducer纠错功能 
// eslint-disable-next-line import/no-anonymous-default-export
export default (state = defaultState, action: LanguageActionTypes) => {
  let states = JSON.parse(JSON.stringify(defaultState))
  if (action.type === CHANGE_LANGUAGE) {
    states.language = action.value === '中文' ? 'zh' : 'en'
    return states
  }
  return state
}